博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MVC引用asp.net报表(测试小例子)
阅读量:5064 次
发布时间:2019-06-12

本文共 5630 字,大约阅读时间需要 18 分钟。

1  public class Default1Controller : Controller 2     { 3         // 4         // GET: /Default1/ 5  6         public ActionResult Index() 7         { 8             return View(); 9         }10 11         public JsonResult ReportFileName()12         {13             DirectoryInfo d = new DirectoryInfo(Server.MapPath("~/") + "Report/");14             FileSystemInfo[] fsinfos = d.GetFileSystemInfos();15             List
fileName = fsinfos.Where(p => p.Name.IndexOf(".rdlc", StringComparison.Ordinal) == -1).Select(fsinfo => fsinfo.Name.Replace(".rdl", "")).ToList();16 return Json(new { Result = fileName });17 }18 19 public JsonResult ExistsFile(string keyId)20 {21 string path = Server.MapPath("~/") + "Report/" + keyId + ".rdl";22 return this.Json(new { ResultBool = System.IO.File.Exists(path) });23 }24 }
MVC后端
1 @{ 2     ViewBag.Title = "Index"; 3 } 4  5 站点: 6  7  8  9 10 
11 12 13
MVC前端
1  public partial class WebForm1 : System.Web.UI.Page  2     {  3         protected void Page_Load(object sender, EventArgs e)  4         {  5             if (!IsPostBack)  6             {  7                 BindReport(Request["KeyId"]);  8             }  9         } 10  11  12  13  14         private void BindReport(string keyId) 15         { 16             string sql = string.Empty; 17             string site = Request["site"]; 18             switch (keyId) 19             { 20                 case "无标题": 21                     sql = " select * from sysuser"; 22                     if (site.Length > 0) 23                     { 24                         sql += " where defsite like '" + site.Trim() + "%'"; 25                     } 26                     break; 27                 case "有标题": 28                     sql = " select * from facility"; 29                     if (site.Length > 0) 30                     { 31                         sql += " where siteid like '" + site.Trim() + "%'"; 32                     } 33                     break; 34                 case "报表模板": 35                     sql = "SELECT USERID AS SEQ,PERSONID AS KSSJ,DEFSITE AS JSSJ FROM SYSUSER"; 36                     if (site.Length > 0) 37                     { 38                         sql += " where siteid like '" + site.Trim() + "%'"; 39                     } 40                     break; 41                 default: 42                     break; 43             } 44  45             DataTable dt = new DataTable(); 46             ReportViewer1.ProcessingMode = ProcessingMode.Local; 47             ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/") + @"Report/" + keyId + ".rdl"; //可以通过SQL语句传参形式 48             ReportViewer1.LocalReport.EnableExternalImages = true; 49             dt = QueryTable(sql); 50             ReportDataSource rds = new ReportDataSource("DataSet1", dt); //DataSetl报表数据集名称 51             ReportViewer1.LocalReport.DataSources.Clear(); 52             ReportViewer1.LocalReport.DataSources.Add(rds); 53             ReportViewer1.LocalReport.Refresh(); 54             //ClientScript.RegisterClientScriptBlock(ClientScript.GetType(), "MyScript", ""); 55             //Response.Write(""); 56             //string js = 57             //    ""; 69             //Response.Write(js); 70         } 71  72  73  74         ///  75         /// 执行查询语句,返回DataTable 76         ///  77         /// 查询语句 78         /// 
DataTable
79 public static DataTable QueryTable(string sqlString) 80 { 81 82 using (var connection = new OracleConnection("DATA SOURCE=192.168.1.61:5050/Xinsida;USER ID=BKCYUN;PASSWORD=bkc123456;")) 83 { 84 var dt = new DataTable(); 85 try 86 { 87 connection.Open(); 88 var command = new OracleDataAdapter(sqlString, connection); 89 command.Fill(dt); 90 return dt; 91 } 92 catch (Exception e) 93 { 94 throw e; 95 } 96 finally 97 { 98 if (connection.State == ConnectionState.Open) 99 {100 connection.Close();101 }102 }103 }104 }105 protected override void Render(HtmlTextWriter writer)106 {107 using (StringWriter sw = new StringWriter())108 {109 HtmlTextWriter tmpWriter = new HtmlTextWriter(sw);110 base.Render(tmpWriter);111 string val = sw.ToString();112 val = val.Replace(@"!= 'javascript:\'\''", @"!= 'javascript:\'\'' && false");113 writer.Write(val);114 }115 }116 }
WebForm后端
1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ReportBuilderTest1.WebForm1" %> 2  3 <%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %> 4  5  6  7  8  9     
10 11 17 <%-- --%>28 29 30
31
32
33
39
40
34
35
36
37
38
41
42 43
WebForm前端

还有一个文件夹Report下面有.rdl报表。这里就不写了。

转载于:https://www.cnblogs.com/Zhengxue/p/8777944.html

你可能感兴趣的文章
[No0000195]NoSQL还是SQL?这一篇讲清楚
查看>>
IOS开发UI篇--UITableView的自定义布局==xib布局
查看>>
【深度学习】caffe 中的一些参数介绍
查看>>
Python-Web框架的本质
查看>>
Unrecognized Windows Sockets error: 0: JVM_Bind 异常解决办法
查看>>
QML学习笔记之一
查看>>
7NiuYun云存储UploadPicture
查看>>
Window 的引导过程
查看>>
python与 Ajax跨域请求
查看>>
App右上角数字
查看>>
从.NET中委托写法的演变谈开去(上):委托与匿名方法
查看>>
小算法
查看>>
201521123024 《java程序设计》 第12周学习总结
查看>>
贪吃蛇游戏改进
查看>>
新作《ASP.NET MVC 5框架揭秘》正式出版
查看>>
在WPF中使用Caliburn.Micro搭建MEF插件化开发框架
查看>>
IdentityServer4-用EF配置Client(一)
查看>>
WPF程序加入3D模型
查看>>
WPF中实现多选ComboBox控件
查看>>
读构建之法第四章第十七章有感
查看>>